﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Collections;
using System.IO;
using System.Drawing;
using System.Text;

public partial class project1 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        if (Session["name"] == null)
        {
            Response.Redirect("~/error.aspx?");
        }
        string JudgePower = Session["power"].ToString();
        if (JudgePower != "超级管理员" && JudgePower != "仓库管理员" && JudgePower != "销售" && JudgePower != "查询用户" && JudgePower != "工程师" && JudgePower != "主管")
        {

            Response.Redirect("~/PowerError.aspx?");
        }
        if (!IsPostBack)
        {
            this.bind();
        }

    }
    public SqlConnection GetConnection()
    {
        string myStr = ConfigurationManager.AppSettings["ConnectionString"].ToString();
        SqlConnection myConn = new SqlConnection(myStr);
        return myConn;
    }

    protected void bind()
    {
        SqlConnection myConn = GetConnection();
        myConn.Open();
        string sqlStr = "select PID as ID,PName as 项目名,bianhao as 项目编号,PDescribe as 项目描述 from Projects";
        SqlDataAdapter myDa = new SqlDataAdapter(sqlStr, myConn);
        DataSet myDs = new DataSet();
        myDa.Fill(myDs);
        GridView1.DataSource = myDs;
        GridView1.DataKeyNames = new string[] { "ID" };
        GridView1.DataBind();
        myDa.Dispose();
        myDs.Dispose();
        myConn.Close();
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        if (TextBox1.Text == "")
        {
            Response.Write("<script>alert('输入不能为空!')</script>");
        }
        else
        {
            SqlConnection myConn = GetConnection();
            myConn.Open();
            string sqlStr = "select PID as ID,PName as 项目名,bianhao as 项目编号,PDescribe as 项目描述 from Projects where PName like '%" + TextBox1.Text + "%' or bianhao like '%" + TextBox1.Text + "%'";
            SqlDataAdapter myDa = new SqlDataAdapter(sqlStr, myConn);
            DataSet myDs = new DataSet();
            myDa.Fill(myDs);
            GridView1.DataSource = myDs;
            GridView1.DataKeyNames = new string[] { "ID" };
            GridView1.DataBind();
            myDa.Dispose();
            myDs.Dispose();
            myConn.Close();
        }
    }

    protected void Button4_Click(object sender, EventArgs e)
    {
        if (GridView1.SelectedValue != null)
        {
            Session["pid"] = GridView1.SelectedValue.ToString();
            Response.Redirect("~/projectkucun1.aspx?");
        }
        else
            Response.Write("<script>alert('未选择项目!')</script>");
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        bind();
    }
    protected void Button5_Click(object sender, EventArgs e)
    {
        if (GridView1.SelectedValue != null)
        {
            Session["pid"] = GridView1.SelectedValue.ToString();
            Response.Redirect("~/projectdan1.aspx?");
        }
        else
            Response.Write("<script>alert('未选择项目!')</script>");
    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
}